high_sea_sagafandomcom_zh-20200214-history
模組:High Sea Saga
local p = {} local paramtest = require('Module:Paramtest') local default_to = paramtest.default_to local has_content = paramtest.has_content -- Compatibility: Lua-5.1 -- Soruce: http://lua-users.org/wiki/SplitJoin function split(str, pat) local t = {} -- NOTE: use {n = 0} in Lua-5.0 local fpat = "(.-)" .. pat local last_end = 1 local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e+1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t end -- Returns 5 squares, filled with a specific color based on the range. -- @param (pRange:String): The range of cells to color. Syntaxes accepted: "1-5"/"2-3", "1"/"5", "x" -- @param (pColor:String): The CSS color for cells in the range -- @returns: a mw.html Element function p._monsterColorRange( pRange, pColor ) local MAX_CELLS = 5 local min = 0 local max = 0 local splitRange = split(pRange, '-') if(#splitRange > 1) then min = tonumber(splitRange1) or 0 max = tonumber(splitRange2) or 0 elseif(string.lower(pRange) 'x') then min = 1 max = 5 pColor = 'hssColorGray' elseif(tonumber(pRange)) then min = tonumber(pRange) max = tonumber(pRange) end local range_string = mw.html.create('span'):addClass('colorBoxCont'):addClass('hssColorNone') for i=1,MAX_CELLS,1 do range_string:tag('span'):addClass('colorBox'):addClass((i >= min and i <= max) and pColor or ):done() end range_string:tag('span'):addClass('mobile-hide'):css({'display'="none"}):wikitext(pRange):done(); range_string:done(); return tostring(range_string) end -- Should be invoked directly, not through a template. function p.monsterColorRange( pFrame ) local parameters = pFrame.args return p._monsterColorRange( default_to(parameters"range", "1-5"), default_to(parameters"colorname", "hssColorRed") ) end -- Returns a formated table of all the monster ranges -- @param (all:String): The range for the specified color -- @returns: mw.html Table Element function p._monsterColorRangeTable(pGreenRange, pBlueRange, pYellowRange, pRedRange, pPurpleRange, pBlackRange) local GREEN_COLOR = 'hssColorGreen' local BLUE_COLOR = 'hssColorBlue' local YELLOW_COLOR = 'hssColorYellow' local RED_COLOR = 'hssColorRed' local PURPLE_COLOR = 'hssColorPurple' local BLACK_COLOR = 'hssColorBlack' return mw.html.create('table'):attr('border', '0'):css({'text-align'='center'}) :tag('tr') :tag('td'):addClass(GREEN_COLOR):css({'border'='0'}):wikitext("'G'"):done() :tag('td'):css({'border'='0'}):node(p._monsterColorRange(pGreenRange, GREEN_COLOR)):done() :tag('td'):addClass(BLUE_COLOR):css({'border'='0'}):wikitext("'B'"):done() :tag('td'):css({'border'='0'}):node(p._monsterColorRange(pBlueRange, BLUE_COLOR)):done() :tag('td'):addClass(YELLOW_COLOR):css({'border'='0'}):wikitext("'Y'"):done() :tag('td'):css({'border'='0'}):node(p._monsterColorRange(pYellowRange, YELLOW_COLOR)):done() :done() :tag('tr') :tag('td'):addClass(RED_COLOR):css({'border'='0'}):wikitext("'R'"):done() :tag('td'):css({'border'='0'}):node(p._monsterColorRange(pRedRange, RED_COLOR)):done() :tag('td'):addClass(PURPLE_COLOR):css({'border'='0'}):wikitext("'P'"):done() :tag('td'):css({'border'='0'}):node(p._monsterColorRange(pPurpleRange, PURPLE_COLOR)):done() :tag('td'):addClass(BLACK_COLOR):css({'border'='0'}):wikitext("'Bk'"):done() :tag('td'):css({'border'='0'}):node(p._monsterColorRange(pBlackRange, BLACK_COLOR)):done() :done() :done() end -- Creates a monster toc from and to specified values -- Should be invoked directly, not through a template. function p.monsterTOC( pFrame ) local parameters = pFrame.args; local tFrom = tonumber(default_to(parameters"from", 0)) local tTo = tonumber(default_to(parameters"to", 100)) function tTocLink(pNum) return ''..pNum..'' end -- http://stackoverflow.com/questions/1405583/concatenation-of-strings-in-lua local t = { } -- returnStringParts t#t+1 = ' ' t#t+1 = tTocLink(tFrom) for i=tFrom+1,tTo,1 do t#t+1 = "•" t#t+1 = tTocLink(i) end t#t+1 = ' ' return table.concat(t," ") end function p._statStyle(pValue) local t = { "S" = "'S'", "A" = "'A'", "B" = "'B'", "C" = "'C'''", "D" = "D", "E" = "E", "F" = "F" } return tstring.upper(pValue) or pValue end function p._monsterEntry(pID, pName, pSize, pElement, pImage, pHP, pSP, pAtk, pDef, pSpd, pInt, pSkills, pEvolve, pGreenRange, pBlueRange, pYellowRange, pRedRange, pPurpleRange, pBlackRange) local t = { } -- returnStringParts t#t+1 = '|- id="'..pID..'"' t#t+1 = '! colspan="3"|'..pName..' '..pID..'' t#t+1 = '! colspan="2" rowspan="2"| Element' t#t+1 = '| colspan="2" rowspan="2"|'..pElement t#t+1 = '! rowspan="2"| Skill' t#t+1 = '! rowspan="2"| Evolves into' t#t+1 = '! rowspan="2"| Colors Range' t#t+1 = '|-' t#t+1 = '| rowspan="3"|'..pImage t#t+1 = '! colspan="1"| Size' t#t+1 = '| colspan="1"|'..pSize t#t+1 = '|-' t#t+1 = '! colspan="1" | HP' t#t+1 = '! colspan="1" | SP' t#t+1 = '! colspan="1" | Atk' t#t+1 = '! colspan="1" | Def' t#t+1 = '! colspan="1" | Spd' t#t+1 = '! colspan="1" | Int' t#t+1 = '| rowspan="2" |'..pSkills t#t+1 = '| rowspan="2" |'..pEvolve t#t+1 = '| rowspan="2" |'..tostring(p._monsterColorRangeTable(pGreenRange, pBlueRange, pYellowRange, pRedRange, pPurpleRange, pBlackRange)) t#t+1 = '|-' t#t+1 = '|'..p._statStyle(pHP) t#t+1 = '|'..p._statStyle(pSP) t#t+1 = '|'..p._statStyle(pAtk) t#t+1 = '|'..p._statStyle(pDef) t#t+1 = '|'..p._statStyle(pSpd) t#t+1 = '|'..p._statStyle(pInt) t#t+1 = '|-' t#t+1 = '| colspan="13" style="height:4px; background:LightSkyBlue" |' return table.concat(t,"\n") end function p.monsterEntryHeader( pFrame ) return '{|class="wikitable centertext" style="border:1px overflow-x:scroll"\n' end function p.monsterEntry( pFrame ) --local parameters = pFrame.args local parameters = pFrame:getParent().args return p._monsterEntry( tonumber(default_to(parameters"entrynumber", "0")), default_to(parameters"name", "NAME REQUIRED"), default_to(parameters"size", "S"), default_to(parameters"element", "Neutral"), has_content(parameters"img") and " " or "?", default_to(parameters"HP", "F"), default_to(parameters"SP", "F"), default_to(parameters"Atk", "F"), default_to(parameters"Def", "F"), default_to(parameters"Spd", "F"), default_to(parameters"Int", "F"), default_to(parameters"skills", ""), default_to(parameters"evolve", ""), default_to(parameters"green", "1-5"), default_to(parameters"blue", "1-5"), default_to(parameters"yellow", "1-5"), default_to(parameters"red", "1-5"), default_to(parameters"purple", "1-5"), default_to(parameters"black", "1-5") ) end return p